//
//  AlarmFirstTableViewCell.m
//  IntelligentHousehold
//
//  Created by Chen on 2017/6/27.
//  Copyright © 2017年 Cassie. All rights reserved.
//

#import "AlarmFirstTableViewCell.h"


@interface AlarmFirstTableViewCell ()

@property (weak, nonatomic) IBOutlet UIView *view1;
@property (weak, nonatomic) IBOutlet UIView *view2;
@property (weak, nonatomic) IBOutlet UIView *view3;
@property (weak, nonatomic) IBOutlet UIView *view4;
@property (weak, nonatomic) IBOutlet UIView *view5;
@property (weak, nonatomic) IBOutlet UIImageView *imgView1;
@property (weak, nonatomic) IBOutlet UIImageView *imgView2;
@property (weak, nonatomic) IBOutlet UIImageView *imgView3;
@property (weak, nonatomic) IBOutlet UIImageView *imgView4;
@property (weak, nonatomic) IBOutlet UIImageView *imgView5;


/**  */
@property (nonatomic , strong) NSArray *titleArray;
@property (nonatomic , strong) NSArray *imgViewArray;

@end

@implementation AlarmFirstTableViewCell


- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
    self.view1.tag = 2000;
    self.view2.tag = 2001;
    self.view3.tag = 2002;
    self.view4.tag = 2003;
    self.view5.tag = 2004;
    
//    self.view1.layer.borderWidth = 1.5;
//    self.view2.layer.borderWidth = 1.5;
//    self.view3.layer.borderWidth = 1.5;
//    self.view4.layer.borderWidth = 1.5;
//    self.view5.layer.borderWidth = 1.5;
    self.imgView1.hidden = YES;
    self.imgView2.hidden = YES;
    self.imgView3.hidden = YES;
    self.imgView4.hidden = YES;
    self.imgView5.hidden = YES;

    
    self.imgViewArray = @[self.imgView1,self.imgView2,self.imgView3,self.imgView4,self.imgView5];
    self.titleArray = @[@"红外",@"烟雾",@"燃气",@"门磁",@"滴水"];
    [self.view1 addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction:)]];
    [self.view2 addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction:)]];
    [self.view3 addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction:)]];
    [self.view4 addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction:)]];
    [self.view5 addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction:)]];
    
}

- (void)setString:(NSString *)string{
    _string = string;
    
    for (NSInteger i = 0; i<5; i++) {
        if ([self.titleArray[i] isEqualToString:string]) {
            
            UIImageView *tempImgView = self.imgViewArray[i];
            tempImgView.hidden = NO;
            
        } else {
            
            UIImageView *tempImgView = self.imgViewArray[i];
            tempImgView.hidden = YES;
        }
    }
}

- (void)tapAction:(UITapGestureRecognizer *)tap{
    NSInteger index = tap.view.tag - 2000;
    
    for (NSInteger i = 0; i<5; i++) {
        if (i == index) {
            
            UIImageView *tempImgView = self.imgViewArray[i];
            tempImgView.hidden = NO;
            
        } else {
            UIImageView *tempImgView = self.imgViewArray[i];
            tempImgView.hidden = YES;
        }
    }
    
    if ([self.delegate respondsToSelector:@selector(passString:)]) {
        [self.delegate passString:self.titleArray[index]];
    }
    
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
